package com.globalwave.pos.inventory.entity;

import javax.persistence.*;

import org.hibernate.annotations.GenericGenerator;

import com.globalwave.base.BaseEntity;


/**
 * The persistent class for the INVENTORY_ON_HAND_BALANCE database table.
 * 
 */
@Entity
@Table(name="INVENTORY_BALANCE")
public class InventoryBalance extends BaseEntity {
	private static final long serialVersionUID = 1L;

	public static final Short INVENTORY_LOCK_UNSALABLE = 0 ;
	public static final Short INVENTORY_LOCK_SALABLE = 1 ;
	
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="increment")
    @GenericGenerator(name="Inventory_Balance_ID_SEQ", strategy = "increment")
	private Long     id                 ;
	private String   region_code        ;
	private String   warehouse_code     ;
	private Long     stock_item_number  ;
	private Integer  on_hand_quantity   ;
	private Integer  mortgaged_quantity ;
	private Integer  unsalable_quantity ;
	private Integer  safe_quantity      ;
	private Integer  status_            ;
	private Short  pre_tna_status     ;
	private Short  pre_sale_status    ;
	private Long     until_date_time    ;
	private Short  post_tna_status    ;
	private Short  post_sale_status   ;
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getRegion_code() {
		return region_code;
	}
	public void setRegion_code(String region_code) {
		this.region_code = region_code;
	}
	public String getWarehouse_code() {
		return warehouse_code;
	}
	public void setWarehouse_code(String warehouse_code) {
		this.warehouse_code = warehouse_code;
	}
	public Long getStock_item_number() {
		return stock_item_number;
	}
	public void setStock_item_number(Long stock_item_number) {
		this.stock_item_number = stock_item_number;
	}
	public Integer getOn_hand_quantity() {
		return on_hand_quantity;
	}
	public void setOn_hand_quantity(Integer on_hand_quantity) {
		this.on_hand_quantity = on_hand_quantity;
	}
	public Integer getMortgaged_quantity() {
		return mortgaged_quantity;
	}
	public void setMortgaged_quantity(Integer mortgaged_quantity) {
		this.mortgaged_quantity = mortgaged_quantity;
	}
	public Integer getUnsalable_quantity() {
		return unsalable_quantity;
	}
	public void setUnsalable_quantity(Integer unsalable_quantity) {
		this.unsalable_quantity = unsalable_quantity;
	}
	public Integer getSafe_quantity() {
		return safe_quantity;
	}
	public void setSafe_quantity(Integer safe_quantity) {
		this.safe_quantity = safe_quantity;
	}
	public Integer getStatus_() {
		return status_;
	}
	public void setStatus_(Integer status) {
		this.status_ = status;
	}
	public Short getPre_tna_status() {
		return pre_tna_status;
	}
	public void setPre_tna_status(Short pre_tna_status) {
		this.pre_tna_status = pre_tna_status;
	}
	public Short getPre_sale_status() {
		return pre_sale_status;
	}
	public void setPre_sale_status(Short pre_sale_status) {
		this.pre_sale_status = pre_sale_status;
	}
	public Long getUntil_date_time() {
		return until_date_time;
	}
	public void setUntil_date_time(Long until_date_time) {
		this.until_date_time = until_date_time;
	}
	public Short getPost_tna_status() {
		return post_tna_status;
	}
	public void setPost_tna_status(Short post_tna_status) {
		this.post_tna_status = post_tna_status;
	}
	public Short getPost_sale_status() {
		return post_sale_status;
	}
	public void setPost_sale_status(Short post_sale_status) {
		this.post_sale_status = post_sale_status;
	}
	
	// -----------------------------------
	

	@Transient
	private boolean isBefore = false ;


	public void setDateNow(Long dateNow){
		if (dateNow == null) {
			return ;
		}
		isBefore = dateNow.longValue() < this.getUntil_date_time().longValue() ;
	}

	public Short getTna_status() {
		return isBefore?pre_tna_status:post_tna_status;
	}
	
	public Short getSale_status() {
		return isBefore?pre_sale_status:post_sale_status;
	}
}